package com.guowen.myaccount.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

import com.guowen.myaccount.R;

public class DBOpenHelper extends SQLiteOpenHelper {

    public DBOpenHelper(@Nullable Context context) {
        super(context, "tally.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // 创建表示类型的表
        String sql = "create table typetb(" +
                "id integer primary key autoincrement, " +
                "typename varchar(10), " +
                "imageId integer, " +
                "sImageId i" +
                "nteger, kind integer)";
        db.execSQL(sql);

        //创建菜单项
        sql = "create table menutb(" +
                "id integer primary key autoincrement," +
                "imageId integer," +
                "sImageId integer," +
                "menuName varchar(10)," +
                "kind integer)";
        db.execSQL(sql);

        //创建记账表
        sql = "create table accounttb(" +
                "id integer primary key autoincrement," +
                "typename varchar(10)," +
                "sImageId integer," +
                "beizhu varchar(80)," +
                "account varchar(15)," +
                "money float," +
                "time varchar(60)," +
                "year integer,month integer,day integer," +
                "kind integer)";
        db.execSQL(sql);

        //创建推荐表
        sql = "create table recommendtb(" +
                "id integer primary key autoincrement," +
                "typename varchar(10)," +
                "sImageId integer," +
                "beizhu varchar(80)," +
                "account varchar(15)," +
                "money float," +
                "time varchar(60)," +
                "year integer,month integer,day integer," +
                "kind integer," +
                "weight integer)";
        db.execSQL(sql);

        //创建帐户行
        sql = "create table accmanagetb(" +
                "id integer primary key autoincrement," +
                "typename varchar(10)," +
                "beizhu varchar(80)," +
                "money float," +
                "year integer," +
                "month integer," +
                "day integer)";
        db.execSQL(sql);

        insertType(db);

    }

    private void insertType(SQLiteDatabase db) {
        // 向db表当中插入元素
        String sql = "insert into typetb (typename,imageId,sImageId,kind) values (?,?,?,?)";
        db.execSQL(sql, new Object[]{"其他", R.mipmap.ic_qita,R.mipmap.ic_qita_fs,0});
        db.execSQL(sql, new Object[]{"餐饮", R.mipmap.ic_canyin,R.mipmap.ic_canyin_fs,0});
        db.execSQL(sql, new Object[]{"交通", R.mipmap.ic_jiaotong,R.mipmap.ic_jiaotong_fs,0});
        db.execSQL(sql, new Object[]{"购物", R.mipmap.ic_gouwu,R.mipmap.ic_gouwu_fs,0});
        db.execSQL(sql, new Object[]{"服饰", R.mipmap.ic_fushi,R.mipmap.ic_fushi_fs,0});
        db.execSQL(sql, new Object[]{"日用品", R.mipmap.ic_riyongpin,R.mipmap.ic_riyongpin_fs,0});
        db.execSQL(sql, new Object[]{"娱乐", R.mipmap.ic_yule,R.mipmap.ic_yule_fs,0});
        db.execSQL(sql, new Object[]{"零食", R.mipmap.ic_lingshi,R.mipmap.ic_lingshi_fs,0});
        db.execSQL(sql, new Object[]{"烟酒茶", R.mipmap.ic_yanjiu,R.mipmap.ic_yanjiu_fs,0});
        db.execSQL(sql, new Object[]{"学习", R.mipmap.ic_xuexi,R.mipmap.ic_xuexi_fs,0});
        db.execSQL(sql, new Object[]{"医疗", R.mipmap.ic_yiliao,R.mipmap.ic_yiliao_fs,0});
        db.execSQL(sql, new Object[]{"住宅", R.mipmap.ic_zhufang,R.mipmap.ic_zhufang_fs,0});
        db.execSQL(sql, new Object[]{"水电费", R.mipmap.ic_shuidianfei,R.mipmap.ic_shuidianfei_fs,0});
        db.execSQL(sql, new Object[]{"通讯", R.mipmap.ic_tongxun,R.mipmap.ic_tongxun_fs,0});
        db.execSQL(sql, new Object[]{"人情往来", R.mipmap.ic_renqingwanglai,R.mipmap.ic_renqingwanglai_fs,0});

        db.execSQL(sql, new Object[]{"其他", R.mipmap.in_qt,R.mipmap.in_qt_fs,1});
        db.execSQL(sql, new Object[]{"薪资", R.mipmap.in_xinzi,R.mipmap.in_xinzi_fs,1});
        db.execSQL(sql, new Object[]{"奖金", R.mipmap.in_jiangjin,R.mipmap.in_jiangjin_fs,1});
        db.execSQL(sql, new Object[]{"借入", R.mipmap.in_jieru,R.mipmap.in_jieru_fs,1});
        db.execSQL(sql, new Object[]{"收债", R.mipmap.in_shouzhai,R.mipmap.in_shouzhai_fs,1});
        db.execSQL(sql, new Object[]{"利息收入", R.mipmap.in_lixifuji,R.mipmap.in_lixifuji_fs,1});
        db.execSQL(sql, new Object[]{"投资回报", R.mipmap.in_touzi,R.mipmap.in_touzi_fs,1});
        db.execSQL(sql, new Object[]{"意外所得", R.mipmap.in_yiwai,R.mipmap.in_yiwai_fs,1});

        sql = "insert into menutb (imageId, sImageId,menuName,kind) values (?,?,?,?)";
        db.execSQL(sql, new Object[]{R.mipmap.home,R.mipmap.home_fs,"首页",0});
        db.execSQL(sql, new Object[]{R.mipmap.history,R.mipmap.history_fs,"历史查看",0});
        db.execSQL(sql, new Object[]{R.mipmap.statistics,R.mipmap.statistics_fs,"分析统计",0});
        db.execSQL(sql, new Object[]{R.mipmap.sort,R.mipmap.sort_fs,"分类管理",0});
        db.execSQL(sql, new Object[]{R.mipmap.account,R.mipmap.account_fs,"账户管理",0});
        db.execSQL(sql, new Object[]{R.mipmap.personal,R.mipmap.personal_fs,"个人中心",0});

        db.execSQL(sql, new Object[]{R.mipmap.recommend,R.mipmap.recommend_fs,"餐饮推荐",1});
        db.execSQL(sql, new Object[]{R.mipmap.backup,R.mipmap.backup_fs,"立即备份",1});
        db.execSQL(sql, new Object[]{R.mipmap.pay,R.mipmap.pay_fs,"捐赠作者",1});
        db.execSQL(sql, new Object[]{R.mipmap.settings,R.mipmap.settings_fs,"设置",1});
        db.execSQL(sql, new Object[]{R.mipmap.out,R.mipmap.out_fs,"退出",1});

        sql = "insert into accmanagetb (typename, beizhu, money, year, month, day) values (?,?,?,?,?,?)";
        db.execSQL(sql, new Object[]{"现金","现金",0,2021,11,16});
        db.execSQL(sql, new Object[]{"微信","网络账户",0,2021,11,16});
        db.execSQL(sql, new Object[]{"支付宝","网络账户",0,2021,11,16});
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
